  # Robustness analysis - Skin Color

# Now, I should also change the dependent variables considering other
# and same race based also on skin color. The variables are:
# ssi_all_race_2_std, ssi_same_skin_group_2_std, ssi_other_race_group_2_std
same_supply_2_sg <- regressions_1(dep_var = "ssi_same_skin_group_2_std",
                                race_var = "skin_group_2",
                                grade_var = "grades_score")

all_supply_2_sg <- regressions_1(dep_var = "ssi_all_race_2_std",
                               race_var = "skin_group_2",
                               grade_var = "grades_score")

other_supply_2_sg <- regressions_1(dep_var = "ssi_other_race_skin_group_2_std",
                                 race_var = "skin_group_2",
                                 grade_var = "grades_score")

variables_to_omit <- "(age)|(male)|(religion)|(class_id)|(avg_)|(class)|(school)|(missing)|(EM)|
                      |(sh)|(poverty)|(Constant)|(supply)|
|(score_nei)|(score_sel)|(score_pare)|(score_study)|(occ_)"

cov_var_labels_control_sg_lin <- c("Dark Skin", "Grades", "Dark Skin*Grades")

list_regs_c <- list(same_supply_2_sg[[3]][[2]], same_supply_2_sg[[3]][[4]],
                    same_supply_2_sg[[3]][[7]],
                    other_supply_2_sg[[3]][[2]], other_supply_2_sg[[3]][[4]],
                    other_supply_2_sg[[3]][[7]],
                    all_supply_2_sg[[3]][[2]], all_supply_2_sg[[3]][[4]],
                    all_supply_2_sg[[3]][[7]])

list_regs <- list(same_supply_2_sg[[1]][[2]], same_supply_2_sg[[1]][[4]],
                  same_supply_2_sg[[1]][[7]],
                  other_supply_2_sg[[1]][[2]], other_supply_2_sg[[1]][[4]],
                  other_supply_2_sg[[1]][[7]],
                  all_supply_2_sg[[1]][[2]], all_supply_2_sg[[1]][[4]],
                  all_supply_2_sg[[1]][[7]])

n_obs <- sapply(list_regs, get_obs)

r_adj <- sapply(list_regs, get_adj_r)

testing <- sapply(list_regs, 
                  function(x) race_score_linear_test(x, 
                                                     race_inter = "skin_group_2", 
                                                     test_var = 'grades_score'))
F_results <- round(c(testing[1,]),3)
P_results <- round(c(testing[2,]),3)


stargazer(list_regs_c, 
          column.separate = c(3,3,3),
          covariate.labels = cov_var_labels_control_sg_lin,
          dep.var.labels.include = F,
          dep.var.caption = "Social status",
          column.labels = c("Same race", "Other races", "All races"),
          omit = variables_to_omit, 
          omit.stat = c("f", "rsq","ser"),
          add.lines = list(c("Linear Hypothesis:", "",  "",  "",  "",  "",  "",  "",  "",  ""),
                           c("F-statistic:",  F_results),
                           c("P-value", P_results),
                           c("Controls:", "",  "",  "",  "",  "",  "",  "",  "",  ""),
                           c("Individual controls", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes"),
                           c("SES controls", "No", "Yes", "Yes", "No", "Yes", "Yes", "No", "Yes", "Yes"),
                           c("Classroom FE", "No", "No", "Yes", "No", "No", "Yes", "No", "No", "Yes"),
                           c("Observation", n_obs),
                           c("Adjusted R2", r_adj)),
          column.sep.width = "0pt",
          font.size = "tiny", type = "text")

stargazer(list_regs_c, 
          column.separate = c(3,3,3),
          covariate.labels = cov_var_labels_control_sg_lin,
          dep.var.labels.include = F,
          dep.var.caption = "Social status",
          column.labels = c("Same race", "Other races", "All races"),
          omit = variables_to_omit, 
          omit.stat = c("f", "rsq","ser"),
          add.lines = list(c("Linear Hypothesis:", "",  "",  "",  "",  "",  "",  "",  "",  ""),
                           c("F-statistic:",  F_results),
                           c("P-value", P_results),
                           c("Controls:", "",  "",  "",  "",  "",  "",  "",  "",  ""),
                           c("Individual controls", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes"),
                           c("SES controls", "No", "Yes", "Yes", "No", "Yes", "Yes", "No", "Yes", "Yes"),
                           c("Classroom FE", "No", "No", "Yes", "No", "No", "Yes", "No", "No", "Yes"),
                           c("Observation", n_obs),
                           c("Adjusted R2", r_adj)),
          column.sep.width = "-5pt",
          font.size = "footnotesize", type = "latex", 
          out = "tables/regs_1_skin_group.tex",
          label = "regs_1_skin_group",
          title = "Skin color, grades, and social status")
